define(function(require){
    $(function(){
    	/*---------- 操作日志——管理员 ----------*/
        /* 表格 */
    	var bodyTemplate = ['<tr traffic_id="{traffic_id}">',
	    	                    '<td class="txtc">{username}</td>',
	    	                    '<td class="txtc">{time}</td>',
	    	                    '<td class="txtc">{operation}</td>',
	    	                    '<td class="txtc">{objectid}</td>',
	    	                    '<td class="txtc">{objectname}</td>',
	    	                    '<td class="txtc">{details}</td>',
		                     '</tr>'].join('');
        
        var date = $('[name=reservation]').val().split(' 至 ');
        var grid = Grid.init({
	            holder:'operationLog',
	            bodyTemplate:bodyTemplate,
	            dataSource:'/trp/operationlog/get_logs/',
	            pageTemplate:semi.grid.pageTemplate,
	            sendOnPageSize: true
	        });
        grid.modifyModel(function(data){
        	data.time = data.time.replace('T',' ');
    	});
        
        /* 数据搜索 */
        var filterData = function(){
        	var txt = $('.searchbox-ipt').val(),
            	d = $('[name=reservation]').val().split(' 至 '),
            	size = $('.pageheader [name=measure]').val(),
            	width = '', height = '',
            	pageSize = 20;
        	
        	if(!semi.utils.isEmpty(size)){
	    		size = size.split('x');
	    		width = size[0];
	    		height = size[1];
	    	}
        	if($('select.page-size').size()>0){
        		pageSize = $('select.page-size').val();
        	}
            grid.send({
        		search_text: txt,
        		start: d[0],
        		end: d[1],
        		width: width,
	        	height: height,
        		pageSize: pageSize,
        		pageNo: 1
        	});
        };
        filterData();
        
        //按时间模糊搜索
        $('input[name=reservation]').daterangepicker({
        	opens: 'left',
            format:'YYYY-MM-DD'
        }, function(start, end, label) {
        	console.log(start.toISOString(), end.toISOString(), label);
        	filterData();
        });
        
        //按用户模糊搜索
        $('.pageheader .searchbox-btn').on('click', filterData);
        $('.pageheader .searchbox-ipt').on('keyup', function(e){
        	if(e.keyCode==semi.keyCode.ENTER){
        		filterData();
        	}
        });
    });
});